package com.catmiao.spark.stream

import org.apache.spark.SparkConf
import org.apache.spark.streaming.dstream.{DStream, ReceiverInputDStream}
import org.apache.spark.streaming.{Seconds, StreamingContext}

/**
 * @title: SparkStreaming01_WordCount
 * @projectName spark_study
 * @description: TODO
 * @author ChengMiao
 * @date 2024/3/25 00:31
 */
object SparkStreaming07_Join {

  def main(args: Array[String]): Unit = {


    val sparkConf: SparkConf = new SparkConf().setMaster("local[*]").setAppName("SparkStreaming")
    val ssc = new StreamingContext(sparkConf, Seconds(5))

    val lines9999: ReceiverInputDStream[String] = ssc.socketTextStream("localhost", 9999)
    val lines8888: ReceiverInputDStream[String] = ssc.socketTextStream("localhost", 8888)

    val v1: DStream[(String, Int)] = lines9999.map((_, 9999))
    val v2: DStream[(String, Int)] = lines8888.map((_, 8888))

    val value: DStream[(String, (Int, Int))] = v1.join(v2)

    value.print()

    ssc.start()
    ssc.awaitTermination()
  }


}
